home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club (Business) 1997 July / Software of the Month Club - Business (Volume 239) (July 1997).iso / pc / code / shared.dxr / 04479_ANIMATOR.ls < prev    next >
Encoding:
Text File  |  1996-02-21  |  10.3 KB  |  327 lines

  1. property pChannel, pStartLoc, pFrameDataStart, pFrameData, pPathData, pSoundType, pSoundName, pIterations, pFrameRate, pbEveryFrame, pbPauseState, pbBackwards, pInkEffect, pbPreload, pScalePct, pLoopAction, pCompletionAction, pbVisibleState, pCurrentTime, pCurrentFrame, pAnimationFrames, pAnimationDuration, pPathFrames, pCurrentPathFrame, pStartTicks, pOffsetTicks, pTicksPerFrame, pLoopCounter, pCurrentLoc, pPathFunctionData, pbPathFunction, pDroppedFrames, pLastProfileTime, pProfilePeriod
  2. global gAnimationObjects, gAnimationChannelStart, gDeathRow, gPathSep, cNullCast
  3.  
  4. on birth me, arguments
  5.   set the pChannel of me to the Channel of arguments
  6.   if the location of arguments = #NULL then
  7.     set the pStartLoc of me to the loc of sprite the pChannel of me
  8.   else
  9.     set the pStartLoc of me to the location of arguments
  10.   end if
  11.   set the pCurrentLoc of me to the pStartLoc of me
  12.   set the pFrameDataStart of me to the frameDataStart of arguments
  13.   if listp(the frameData of arguments) then
  14.     if stringp(getAt(the frameData of arguments, 1)) then
  15.       set theCount to count(the frameData of arguments)
  16.       repeat with X = 1 to theCount
  17.         setAt(the frameData of arguments, X, the number of cast getAt(the frameData of arguments, X))
  18.       end repeat
  19.     end if
  20.     set the pFrameData of me to the frameData of arguments
  21.   else
  22.     set the pFrameData of me to [the pFrameDataStart of me]
  23.     sort(the pFrameData of me)
  24.     set nextFrame to the pFrameDataStart of me
  25.     repeat while nextFrame < the frameData of arguments
  26.       set nextFrame to nextFrame + 1
  27.       add(the pFrameData of me, nextFrame)
  28.     end repeat
  29.   end if
  30.   preLoadData(me)
  31.   set the pbPathFunction of me to 0
  32.   if the pathData of arguments = #NULL then
  33.     set the pPathData of me to []
  34.   else
  35.     if symbolp(the pathData of arguments) then
  36.       set the pbPathFunction of me to 1
  37.       set the pPathFunctionData of me to the pathData of arguments
  38.       set the pPathData of me to []
  39.     else
  40.       set the pPathData of me to the pathData of arguments
  41.     end if
  42.   end if
  43.   set the pSoundType of me to the soundType of arguments
  44.   set the pSoundName of me to the soundName of arguments
  45.   set theIterations to the iterations of arguments
  46.   if theIterations = #INFINITE then
  47.     set the pIterations of me to the maxinteger
  48.   else
  49.     set the pIterations of me to theIterations
  50.   end if
  51.   set the pLoopCounter of me to 0
  52.   set theFrameRate to the frameRate of arguments
  53.   if theFrameRate = #NULL then
  54.     set the pFrameRate of me to the frameTempo
  55.   else
  56.     set the pFrameRate of me to theFrameRate
  57.   end if
  58.   set the pbEveryFrame of me to 1
  59.   set the pbPauseState of me to 0
  60.   set the pbBackwards of me to 0
  61.   set theInkEffects to the inkEffect of arguments
  62.   if theInkEffects = #NULL then
  63.     set the pInkEffect of me to 0
  64.   else
  65.     set the pInkEffect of me to getaProp([#COPY: 0, #MATTE: 8, #BKTRANS: 36], theInkEffects)
  66.   end if
  67.   set the ink of sprite the pChannel of me to the pInkEffect of me
  68.   set the pScalePct of me to 100
  69.   set theLoopAction to the loopAction of arguments
  70.   if theLoopAction = #NULL then
  71.     set the pLoopAction of me to #repeat
  72.   else
  73.     set the pLoopAction of me to theLoopAction
  74.   end if
  75.   set theCompletionArguments to the completionAction of arguments
  76.   if theCompletionArguments = #NULL then
  77.     set the pCompletionAction of me to #death
  78.   else
  79.     set the pCompletionAction of me to theCompletionArguments
  80.   end if
  81.   set the pbVisibleState of me to 1
  82.   SoundAnimation(me)
  83.   VisualizeAnimation(me)
  84.   set the pCurrentTime of me to 0
  85.   set the pCurrentFrame of me to 1
  86.   set the pCurrentPathFrame of me to 1
  87.   set the pStartTicks of me to the ticks
  88.   set the pOffsetTicks of me to the pStartTicks of me
  89.   set thepFrameRate to the pFrameRate of me
  90.   if thepFrameRate < 61 then
  91.     set the pTicksPerFrame of me to 60 / thepFrameRate
  92.   else
  93.     set the pTicksPerFrame of me to 60 / float(thepFrameRate)
  94.   end if
  95.   set the pAnimationFrames of me to count(the pFrameData of me)
  96.   set the pPathFrames of me to count(the pPathData of me)
  97.   set the pAnimationDuration of me to the pAnimationFrames of me * the pTicksPerFrame of me
  98.   return me
  99. end
  100.  
  101. on addUnique theList, theItem
  102.   if getOne(theList, theItem) = 0 then
  103.     add(theList, theItem)
  104.   end if
  105. end
  106.  
  107. on SoundAnimation me
  108.   set soundType to the pSoundType of me
  109.   set soundName to the pSoundName of me
  110.   if soundType <> #NULL then
  111.     if (soundType = #File) or (soundType = #animatorFile) then
  112.       playSound(soundName, #animatorFile)
  113.     else
  114.       if soundType = #FileLooped then
  115.         playSound(soundName, #animatorFile)
  116.       else
  117.         if (soundType = #cast) or (soundType = #animatorCast) then
  118.           playSound(soundName, #animatorCast)
  119.         end if
  120.       end if
  121.     end if
  122.   end if
  123. end
  124.  
  125. on VisualizeAnimation me
  126.   if pLoopAction = #PALINDROME then
  127.     MakePalindromeList(me)
  128.   end if
  129.   set the castNum of sprite the pChannel of me to the pFrameDataStart of me
  130.   SizeSprite(me)
  131.   if not (the pbVisibleState of me) then
  132.     setVisibleState(me, 0)
  133.   else
  134.     set the loc of sprite the pChannel of me to the pCurrentLoc of me
  135.   end if
  136. end
  137.  
  138. on death me
  139.   set theSoundName to the pSoundName of me
  140.   if theSoundName <> #NULL then
  141.     stopSound(the pSoundName of me)
  142.   end if
  143.   set the castNum of sprite the pChannel of me to cNullCast
  144.   set the loc of sprite the pChannel of me to point(2000, 2000)
  145.   set the ink of sprite the pChannel of me to 36
  146.   deleteProp(gAnimationObjects, the pChannel of me)
  147. end
  148.  
  149. on stepAnimation me
  150.   set elapsedTicks to CheckEXITS(me)
  151.   if elapsedTicks = #exit then
  152.     exit
  153.   end if
  154.   set the pCurrentFrame of me to the pCurrentFrame of me + 1
  155.   if LoopAnimation(me) <> #exit then
  156.     set the castNum of sprite the pChannel of me to getAt(the pFrameData of me, the pCurrentFrame of me)
  157.     moveSprite(me)
  158.   end if
  159.   set the pCurrentTime of me to the ticks - the pOffsetTicks of me
  160. end
  161.  
  162. on CheckEXITS me
  163.   if the pbPauseState of me then
  164.     return #exit
  165.   end if
  166.   if not (the pbVisibleState of me) then
  167.     return #exit
  168.   end if
  169.   set elapsedTicks to the ticks - the pOffsetTicks of me - the pCurrentTime of me
  170.   if elapsedTicks < the pTicksPerFrame of me then
  171.     return #exit
  172.   end if
  173.   return elapsedTicks
  174. end
  175.  
  176. on LoopAnimation me
  177.   if the pCurrentFrame of me > the pAnimationFrames of me then
  178.     set the pCurrentFrame of me to 1
  179.     set the pLoopCounter of me to the pLoopCounter of me + 1
  180.     if the pLoopCounter of me < the pIterations of me then
  181.       if pLoopAction = #pause then
  182.         setPauseState(me, 1)
  183.         return #exit
  184.       else
  185.         set the pOffsetTicks of me to the ticks
  186.         if not (the pbPathFunction of me) then
  187.           set the pCurrentLoc of me to the pStartLoc of me
  188.         end if
  189.         return #continue
  190.       end if
  191.     else
  192.       if the pCompletionAction of me = #death then
  193.         addUnique(gDeathRow, the pChannel of me)
  194.         return #exit
  195.       else
  196.         if the pCompletionAction of me = #pause then
  197.           setPauseState(me, 1)
  198.           return #exit
  199.         else
  200.           if stringp(the pCompletionAction of me) then
  201.             do(the pCompletionAction of me)
  202.             setPauseState(me, 1)
  203.             return #exit
  204.           end if
  205.         end if
  206.       end if
  207.     end if
  208.     return #continue
  209.   end if
  210. end
  211.  
  212. on moveSprite me
  213.   if the pbPathFunction of me then
  214.     if pPathFunctionData = #ranStockloc then
  215.       set theResult to ranStockloc(me)
  216.     else
  217.       if pPathFunctionData = #trendbarStockloc then
  218.         set theResult to trendbarStockloc(me)
  219.       else
  220.         if pPathFunctionData = #pricePriceLoc then
  221.           set theResult to pricePriceLoc(me)
  222.         end if
  223.       end if
  224.     end if
  225.     set the pCurrentLoc of me to theResult
  226.   else
  227.     if count(pPathData) = 0 then
  228.       exit
  229.     end if
  230.     set currentPathData to getAt(the pPathData of me, the pCurrentFrame of me)
  231.     set the pCurrentLoc of me to the pCurrentLoc of me + currentPathData
  232.   end if
  233.   set the loc of sprite the pChannel of me to the pCurrentLoc of me
  234. end
  235.  
  236. on SizeSprite me
  237.   if the pScalePct of me = 100 then
  238.     exit
  239.   end if
  240.   set theCast to the castNum of sprite the pChannel of me
  241.   set theSourceRect to the rect of cast theCast
  242.   set width to the width of cast theCast
  243.   set height to the height of cast theCast
  244.   set adjustPct to (the pScalePct of me - 100) / 200.0
  245.   set the rect of sprite the pChannel of me to inflate(theSourceRect, width * adjustPct, height * adjustPct)
  246. end
  247.  
  248. on setCurrentLoc me, thePoint
  249.   set the pCurrentLoc of me to thePoint
  250.   set the loc of sprite the pChannel of me to the pCurrentLoc of me
  251. end
  252.  
  253. on setCurrentFrame me, frame
  254.   if frame = #Start then
  255.     set the pCurrentFrame of me to 1
  256.   else
  257.     if frame = #end then
  258.       set the pCurrentFrame of me to the pAnimationFrames of me
  259.     else
  260.       set the pCurrentFrame of me to frame
  261.     end if
  262.   end if
  263. end
  264.  
  265. on setPauseState me, State
  266.   set the pbPauseState of me to State
  267. end
  268.  
  269. on pauseToggle me
  270.   set the pbPauseState of me to not (the pbPauseState of me)
  271. end
  272.  
  273. on setVisibleState me, State
  274.   set the pbVisibleState of me to State
  275.   hideUnhide(me)
  276. end
  277.  
  278. on visibleToggle me
  279.   set the pbVisibleState of me to not (the pbVisibleState of me)
  280.   hideUnhide(me)
  281. end
  282.  
  283. on hideUnhide me
  284.   if the pbVisibleState of me then
  285.     set the loc of sprite the pChannel of me to the pCurrentLoc of me
  286.   else
  287.     set the loc of sprite the pChannel of me to point(-20000, -20000)
  288.   end if
  289.   updateStage()
  290. end
  291.  
  292. on MakePalindromeList me
  293.   set aStart to count(the pFrameData of me)
  294.   if (aStart > 2) and (pPathData = #NULL) then
  295.     repeat with frame = aStart down to 2
  296.       add(the pFrameData of me, getAt(the pFrameData of me, frame))
  297.     end repeat
  298.   else
  299.     if (aStart > 2) and (count(pPathData) = aStart) then
  300.       repeat with frame = aStart - 1 down to 2
  301.         add(the pFrameData of me, getAt(the pFrameData of me, frame))
  302.       end repeat
  303.       repeat with frame = aStart down to 2
  304.         set newdata to -getAt(the pPathData of me, frame)
  305.         add(the pPathData of me, newdata)
  306.       end repeat
  307.     end if
  308.   end if
  309. end
  310.  
  311. on reverseFrameData me
  312.   set reversedFrameData to []
  313.   repeat with frame = the pAnimationFrames of me down to 1
  314.     add(reversedFrameData, getAt(the pFrameData of me, frame))
  315.   end repeat
  316.   set the pFrameData of me to value(string(reversedFrameData))
  317.   set the pCurrentFrame of me to the pAnimationFrames of me - the pCurrentFrame of me
  318. end
  319.  
  320. on preLoadData me
  321.   if the pbPreload of me then
  322.     repeat with castOffset in the pFrameData of me
  323.       preLoadCast(castOffset)
  324.     end repeat
  325.   end if
  326. end
  327.